Imports CapaDeDatos
Public Class nFacOtras
    Public FacOtras As CapaDeDatos.dFacOtras = New CapaDeDatos.dFacOtras
    Public FacCuentas As CapaDeDatos.dFacCuenta = New CapaDeDatos.dFacCuenta
    Public Faccheque As CapaDeDatos.dFacCheque = New CapaDeDatos.dFacCheque
    Public Cheque As CapaDeDatos.dChequesPropios = New CapaDeDatos.dChequesPropios
    Public Factura As CapaDeDatos.dFacturaCompra = New CapaDeDatos.dFacturaCompra
    Public Imputacion As CapaDeDatos.dImputacion = New CapaDeDatos.dImputacion

    Public Function InsertarRegistro(ByVal CodigoFactura As String, _
    ByVal CodigoImputacion As String, ByVal Importe As String, ByVal Fecha As String) As Boolean
        Return FacOtras.Insertar(CodigoFactura, CodigoImputacion, Importe, Fecha)
    End Function
    Public Function JuntaCuentas(ByVal CodigoFactura As Integer) As DataSet
        Dim dtsPrincipal As DataSet
        Dim dtsAuxiliar As DataSet
        dtsAuxiliar = New DataSet()
        dtsPrincipal = New DataSet()

        Dim Tbluno As DataTable = dtsAuxiliar.Tables.Add("Tbluno")
        Dim TblDos As DataTable = dtsAuxiliar.Tables.Add("TblDos")
        Dim TblTres As DataTable = dtsAuxiliar.Tables.Add("TblTres")

        Tbluno = (FacCuentas.BuscarFiltrado("", "", CodigoFactura, "", "").Tables(0))
        TblDos = (FacOtras.BuscarFiltrado("", CodigoFactura, "", "", "").Tables(0))
        TblTres = (Faccheque.BuscarFiltrado("", CodigoFactura, "", "", "").Tables(0))
        
        dtsAuxiliar.Tables.Add("TblUno")
        dtsAuxiliar.Tables.Add("Tbldos")
        dtsAuxiliar.Tables.Add("Tbltres")


        dtsPrincipal.Tables.Add("TblNueva")
        dtsPrincipal.Tables(0).Columns.Add(New DataColumn("Numero"))
        dtsPrincipal.Tables(0).Columns.Add(New DataColumn("CodigoFactura"))
        dtsPrincipal.Tables(0).Columns.Add(New DataColumn("Fecha"))
        dtsPrincipal.Tables(0).Columns.Add(New DataColumn("CodigoImputacion"))
        dtsPrincipal.Tables(0).Columns.Add(New DataColumn("DescripcionImp"))
        dtsPrincipal.Tables(0).Columns.Add(New DataColumn("Cheque"))
        dtsPrincipal.Tables(0).Columns.Add(New DataColumn("Importe"))
        Dim i As Integer
        Dim dr As DataRow

        For i = 0 To Tbluno.Rows.Count - 1
            'con cheque
            dr = dtsPrincipal.Tables(0).NewRow()
            dr("Numero") = Factura.NumeroFactura(Int(Tbluno.Rows(i)("CodigoFactura").ToString()))
            dr("Fecha") = CDate(Tbluno.Rows(i)("Fecha").ToString()).ToShortDateString()
            dr("CodigoImputacion") = Tbluno.Rows(i)("CodigoCuenta").ToString()
            dr("CodigoFactura") = Tbluno.Rows(i)("CodigoFactura").ToString()
            dr("DescripcionImp") = "Banco"
            dr("Importe") = Tbluno.Rows(i)("Importe").ToString()
            dtsPrincipal.Tables(0).Rows.Add(dr)
        Next
        For i = 0 To TblDos.Rows.Count - 1
            'con efectivo
            dr = dtsPrincipal.Tables(0).NewRow()
            dr("Numero") = Factura.NumeroFactura(Int(TblDos.Rows(i)("CodigoFactura").ToString()))
            dr("Fecha") = CDate(TblDos.Rows(i)("Fecha").ToString()).ToShortDateString()
            dr("CodigoImputacion") = TblDos.Rows(i)("CodigoImputacion").ToString()
            dr("CodigoFactura") = TblDos.Rows(i)("CodigoFactura").ToString()
            dr("DescripcionImp") = "Caja"
            dr("Importe") = TblDos.Rows(i)("Importe").ToString()
            dtsPrincipal.Tables(0).Rows.Add(dr)
        Next
        For i = 0 To TblTres.Rows.Count - 1
            'con cuenta
            dr = dtsPrincipal.Tables(0).NewRow()
            dr("Numero") = Factura.NumeroFactura(Int(TblTres.Rows(i)("CodigoFactura").ToString()))
            dr("Fecha") = CDate(TblTres.Rows(i)("Fecha").ToString()).ToShortDateString()
            dr("CodigoImputacion") = "Banco"
            dr("DescripcionImp") = "Cheque : " + TblTres.Rows(i)("IdCheque").ToString()
            dr("Importe") = TblTres.Rows(i)("Importe").ToString()
            dtsPrincipal.Tables(0).Rows.Add(dr)
        Next

        Return dtsPrincipal
    End Function
End Class
